package cn.hr.service.impl;

import cn.hr.dao.mapper.RecruitMapper;
import cn.hr.pojo.Recruit;
import cn.hr.service.RecruitService;
import cn.hr.utils.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 招聘信息服务接口实现类
 *
 * @author MO
 */
@CacheConfig(cacheNames = "recruit")
@Scope("prototype")
@Service("recruitService")
public class RecruitServiceImpl implements RecruitService {
    @Resource
    private RecruitMapper recruitMapper;

    @Override
    public boolean insert(Recruit t) throws Exception {
        t.setCode("RECR_CODE_"+(recruitMapper.findMaxId()+1));
        return recruitMapper.insert(t) > 0;
    }

    @Override
    public boolean update(Recruit t) throws Exception {
        return recruitMapper.update(t) > 0;
    }

    @Override
    public boolean delete(Integer id) throws Exception {
        return recruitMapper.delete(id) > 0;
    }

    @Override
    public Recruit get(Integer id) throws Exception {
        return recruitMapper.get(id);
    }


    @Override
    public PageInfo<Map> findListByCondition(Map m, int pageNo) throws Exception {
        PageHelper.startPage(pageNo, Constants.PAGESIZE);
        PageInfo<Map> pageInfo = new PageInfo<>(recruitMapper.findListByCondition(m));
        return pageInfo;
    }

    @Override
    public Long findCountByCondition(Map m) throws Exception {
        return recruitMapper.findCountByCondition(m);
    }

}
